// by Xeno
//#define __DEBUG__
#define THIS_FILE "fn_createprioritytargetclient.sqf"
#include "x_setup.sqf"
if (!X_Client) exitWith{};
private ["_current_target_name","_current_target_pos","_marker","_t_array","_current_target_radius","_current_target_index","_position","_show_notification"];
_show_notification = (!(isNil "_this") && { typename _this == typename true } && { _this });
waitUntil {!isNil {__XJIPGetVar(GVAR(current_target_index))}};
_current_target_index = __XJIPGetVar(GVAR(current_target_index));
if (_current_target_index < 0) exitWith {};

sleep 1.012;
_t_array = GVAR(target_names) select _current_target_index;
_current_target_pos = _t_array select 0;
_current_target_name = _t_array select 1;
_current_target_radius = _t_array select 2;

_position = __XJIPGetVar(GVAR(priority_position));

__TRACE_2("Start","_t_array","_position")
if (count _position > 0) then {
	private ["_dtnum", "_dtform", "_dtask","_ptask","_pform"];
	
	#ifndef __TT__
	[format["mtprio_%1",_current_target_index], _position,"ICON","ColorRed",[1,1],format [(localize "STR_DOM_MISSIONSTRING_2059"), _current_target_name],0,"hd_warning"] call FUNC(CreateMarkerLocal);
	#else
	[format["mtprio_%1",_current_target_index], _position,"ICON","ColorYellow",[1,1],format [(localize "STR_DOM_MISSIONSTRING_2059"), _current_target_name],0,"hd_warning"] call FUNC(CreateMarkerLocal);
	#endif
	QGVAR(dummy_marker) setMarkerPosLocal _position;
	
	_d = "";
	_t = "";
	if (__XJIPGetVar(GVAR(prio_kind)) != -1) then {
		switch (__XJIPGetVar(GVAR(prio_kind))) do {
			case 1: {
				_d = format [(localize "STR_DOM_MISSIONSTRING_2060"), _current_target_name];
				_t = format [(localize "STR_DOM_MISSIONSTRING_2069"), _current_target_name];
			};
			case 2: {
				_d = format [(localize "STR_DOM_MISSIONSTRING_2061"), _current_target_name];
				_t = format [(localize "STR_DOM_MISSIONSTRING_2070"), _current_target_name];
			};
			case 3: {
				_d = format [(localize "STR_DOM_MISSIONSTRING_2062"), _current_target_name];
				_t = format [(localize "STR_DOM_MISSIONSTRING_2071"), _current_target_name];
			};
			case 4: {
				_d = format [(localize "STR_DOM_MISSIONSTRING_2063"), _current_target_name];
				_t = format [(localize "STR_DOM_MISSIONSTRING_2072"), _current_target_name];
			};
			case 5: {
				_d = format [(localize "STR_DOM_MISSIONSTRING_2064"), _current_target_name];
				_t = format [(localize "STR_DOM_MISSIONSTRING_2073"), _current_target_name];
			};
			case 6: {
				_d = format [(localize "STR_DOM_MISSIONSTRING_2065"), _current_target_name];
				_t = format [(localize "STR_DOM_MISSIONSTRING_2074"), _current_target_name];
			};
			case 7: {
				_d = format [(localize "STR_DOM_MISSIONSTRING_2066"), _current_target_name];
				_t = format [(localize "STR_DOM_MISSIONSTRING_2075"), _current_target_name];
			};
			case 8: {
				_d = format [(localize "STR_DOM_MISSIONSTRING_2067"), _current_target_name];
				_t = format [(localize "STR_DOM_MISSIONSTRING_2076"), _current_target_name];
			};
		};
	} else {
		_d = (localize "STR_DOM_MISSIONSTRING_2057");
		_t = (localize "STR_DOM_MISSIONSTRING_2068");
	};	
	
	
	_dtnum = _current_target_index + 2;
	_dtform = format ["d_task%1", _dtnum];
	_dtask = __getMNsVar2(_dtform);

	_pform = format["d_prio%1", _dtnum];
	__mNsSetVar [_pform, player createSimpleTask [format ["prio%1", _dtnum], _dtask]];
	__TRACE_1("_pform","_pform")
	sleep 1.013;
	
	_ptask = __getMNsVar2(_pform);
	_ptask setSimpleTaskDescription [_d, _t, format [(localize "STR_DOM_MISSIONSTRING_2059"), _current_target_name]];
	_ptask setTaskState "Created";
	// _ptask setSimpleTaskDestination _position;

	if (_show_notification) then {
		playSound "IncomingChallenge2";
		["TaskCreated",[_ptask, (taskDescription _ptask) select 1]] call BFUNC(showNotification);
		hint format [(localize "STR_DOM_MISSIONSTRING_2058"), _current_target_name];
	};
	__TRACE_2("end","_pform","_ptask")
};